package com.zbf.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;

/** 
 * @author: LCG
 * @date: 2022-06-26 12:08:52
 * @description:  监听环境变量的 变化
 */
@Component
public class DemoEnvironmentChangeListener implements ApplicationListener<EnvironmentChangeEvent> {

 
    @Autowired
    private ConfigurableEnvironment environment;
 
    @Override
    public void onApplicationEvent(EnvironmentChangeEvent event) {
        for (String key : event.getKeys()) {
            System.out.println("[onApplicationEvent][key({}) 最新 value 为 {}] "+key+"="+ environment.getProperty(key));
        }
    }
 
}